//
//  LYQMineSoftFunctionCell.m
//  ZCProject
//
//  Created by Zheng on 16/11/14.
//  Copyright © 2016年 Zheng. All rights reserved.
//

#import "LYQMineSoftFunctionCell.h"

#import "LYQMineTopicMangeViewController.h"
#import "LYQMineResourcesManageViewController.h"
#import "LYQMinePositionManageViewController.h"
#import "LYQMineDemandManageViewController.h"
#import "LYQMineActivityManageViewController.h"

@implementation LYQMineSoftFunctionCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        [self.contentView addSubview:self.bgBtnView];
        
        [self layoutSubviewsInContentView];
        
    }
    return self;
}

#pragma mark - layout subviews
- (void)layoutSubviewsInContentView {
    [_bgBtnView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.bottom.equalTo(self);
    }];
}

#pragma mark - load subviews
- (UIView *)bgBtnView {
    if (!_bgBtnView) {
        _bgBtnView = [[UIView alloc] init];
        
        NSArray *imageNamesArr = @[@"zyicon",@"xqicon",@"m_hticon",@"hdicon",@"zwicon"];
        NSArray *titleNamesArr = @[@"资源",@"需求",@"话题",@"活动",@"职位"];
        
        for (int i = 0; i < 5; i++) {
            
            UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
            [button setImage:[UIImage imageNamed:imageNamesArr[i]] forState:UIControlStateNormal];
            [button setTitle:titleNamesArr[i] forState:UIControlStateNormal];
            button.titleLabel.font = kFont(13);
            [button setTitleColor:kHexadecimal(@"666666") forState:UIControlStateNormal];
            button.frame = CGRectMake(10+i*(kMS_Width-20)/5, 0, (kMS_Width-20)/5, kWScale(80));
            [button addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];
            
            UIEdgeInsets imageEdgeInSets;
            UIEdgeInsets titleEdgeInSets;
            
            if (i == 0) {
                imageEdgeInSets = UIEdgeInsetsMake(-20, 13, 0, 0);
                titleEdgeInSets = UIEdgeInsetsMake(30, -45, 0, 0);
            } else if (i == 1) {
                imageEdgeInSets = UIEdgeInsetsMake(-20, 10, 0, 0);
                titleEdgeInSets = UIEdgeInsetsMake(30, -44, 0, 0);
            } else if (i == 3) {
                imageEdgeInSets = UIEdgeInsetsMake(-20, 10, 0, 0);
                titleEdgeInSets = UIEdgeInsetsMake(30, -39, 0, 0);
            } else {
                imageEdgeInSets = UIEdgeInsetsMake(-20, 10, 0, 0);
                titleEdgeInSets = UIEdgeInsetsMake(30, -42, 0, 0);
            }
            
            [button setImageEdgeInsets:imageEdgeInSets];
            [button setTitleEdgeInsets:titleEdgeInSets];
            
            [_bgBtnView addSubview:button];
        
        }
    }
    return _bgBtnView;
}

#pragma mark - button action
- (void)btnAction:(UIButton *)sender {
    if ([sender.titleLabel.text isEqualToString:@"话题"]) {
#pragma marm 跳转话题管理页面
        LYQMineTopicMangeViewController *mtmVC = [[LYQMineTopicMangeViewController alloc] init];
        mtmVC.hidesBottomBarWhenPushed = YES;
        [self.viewController.navigationController pushViewController:mtmVC animated:YES];
    } else if ([sender.titleLabel.text isEqualToString:@"资源"]) {
#pragma mark 跳转资源管理页面
        LYQMineResourcesManageViewController *mrmVC = [[LYQMineResourcesManageViewController alloc] init];
        mrmVC.hidesBottomBarWhenPushed = YES;
        [self.viewController.navigationController pushViewController:mrmVC animated:YES];
    } else if ([sender.titleLabel.text isEqualToString:@"职位"]) {
#pragma mark 跳转职位管理页面
        LYQMinePositionManageViewController *mpmVC = [[LYQMinePositionManageViewController alloc] init];
        mpmVC.hidesBottomBarWhenPushed = YES;
        [self.viewController.navigationController pushViewController:mpmVC animated:YES];
    } else if ([sender.titleLabel.text isEqualToString:@"需求"]) {
#pragma mark 跳转需求管理页面
        LYQMineDemandManageViewController *mdmVC = [[LYQMineDemandManageViewController alloc] init];
        mdmVC.hidesBottomBarWhenPushed = YES;
        [self.viewController.navigationController pushViewController:mdmVC animated:YES];
    } else {
#pragma mark 跳转活动管理页面
        LYQMineActivityManageViewController *mamVC = [[LYQMineActivityManageViewController alloc] init];
        mamVC.hidesBottomBarWhenPushed = YES;
        [self.viewController.navigationController pushViewController:mamVC animated:YES];
    }
}

@end
